package io.renren.modules.wx.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.modules.wx.entity.BankQuestionEntity;
import io.renren.modules.wx.service.BankQuestionService;
import io.renren.modules.wx.vo.BankQuestionVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.wx.entity.TestEntity;
import io.renren.modules.wx.service.TestService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author linmingze
 * @email ${email}
 * @date 2022-10-21 09:49:34
 */
@RestController
@RequestMapping("wx/test")
public class TestController {
    @Autowired
    private TestService testService;

    @Autowired
    private BankQuestionService bankQuestionService;

    /**
     * 通过studentId查找测试记录
     */
    @GetMapping("/questionAndAnswer")
    @RequiresPermissions("wx:test:list")
    public R getMyAnswer(@RequestParam Map<String, Object> params){

        return R.ok().put("data", testService.getQuestionAndAnswer(params));
    }


    /**
     * 通过studentId查找测试记录
     */
    @GetMapping("/record/{studentId}")
    @RequiresPermissions("wx:test:list")
    public R listByStudentId(@PathVariable("studentId") Integer studentId){

        List<TestEntity> testEntities = testService.listByStudentId(studentId);
        return R.ok().put("data", testEntities);
    }

    /**
     * 提交测试
     */
    @GetMapping("/submit")
    @RequiresPermissions("wx:test:list")
    public R submit(@RequestParam Map<String, Object> params){
        testService.submitTest(params);
        return R.ok();
    }


    /**
     * 通过TestId获取Question列表
     */
    @GetMapping("/question/{testId}")
    @RequiresPermissions("wx:test:list")
    public R queryQuestion(@PathVariable("testId") Integer testId){
        List<BankQuestionVo> entities = bankQuestionService.queryQuestion(testId);
        return R.ok().put("page", entities);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("wx:test:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = testService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{testId}")
    @RequiresPermissions("wx:test:info")
    public R info(@PathVariable("testId") Integer testId){
		TestEntity test = testService.getById(testId);
        return R.ok().put("test", test);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("wx:test:save")
    public R save(@RequestBody TestEntity test){
		testService.save(test);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("wx:test:update")
    public R update(@RequestBody TestEntity test){
		testService.updateById(test);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("wx:test:delete")
    public R delete(@RequestBody Integer[] testIds){
		testService.removeByIds(Arrays.asList(testIds));

        return R.ok();
    }

}
